package com.icss.lesson4;

import java.util.Arrays;

public class Queue {
    private Object[] n = new Object[10];
    private int index;
    public Queue() {
        ;
    }

    public void add(Object e) {
        if (index == n.length - 1) {
            Object[] tmp = new Object[n.length + n.length / 2];
            // 数组copy   原数组 下标0 到  新数组下标 0  copy  n.length个
            System.arraycopy(n, 0, tmp, 0, n.length);
            n = tmp;
        }
        n[index++] = e;
    }
    public Object get() {
        // 数组中清除第一个元素
        //
        Object x = n[0];
        System.arraycopy(n, 1, n, 0, n.length - 1);
        index--;
        return x;
    }

    @Override
    public String toString() {
        return "Queue{" +
                "n=" + Arrays.toString(n) +
                ", index=" + index +
                '}';
    }
}
